/*
 *    Copyright (c) 2019- 2020  autoai All Rights Reserved
 *    FileName: InitRunner.java
 *    ProjectName: autoai-group
 *    @Date:2020/1/7 下午1:28
 *    @Author:guoyb
 *    @version: 1.0
 */

package com.xncoding.pos.init;

import cn.hutool.core.date.SystemClock;
import cn.hutool.core.util.RandomUtil;
import com.xncoding.pos.dao.TbUserDao;
import com.xncoding.pos.model.Person;
import com.xncoding.pos.model.TbUser;
import com.xncoding.pos.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 系统初始化读取配置
 *
 * @Description InitRunner
 * @Author guoyb
 * @Date 2020/1/7 13:28
 */
@Slf4j
@Component
public class InitRunner implements ApplicationRunner {

    @Resource
    MessageService messageService;

    /**
     * 注入bean
     */
    @Resource
    Person person;

    @Resource
    TbUserDao tbUserDao;


    /**
     * 执行初始化加载
     *
     * @param applicationArguments
     * @throws Exception
     */
    @Override
    public void run(ApplicationArguments applicationArguments) throws Exception {
        log.info("ApplicationRunner:根据运行环境,注入不同的bean: person内容: {}", person.toString());


        String message = messageService.getMessage();
        log.info("不同环境,接口的实现类的执行messageService---日志------{}", message);

        // List<TbUser> list = tbUserDao.queryAll(null);
        // if (list.size() < 15) {
        //     TbUser user;
        //     for (int i = 0; i < 15 - list.size(); i++) {
        //         user = new TbUser();
        //         long now = SystemClock.now();
        //         user.setUserName(String.valueOf(now));
        //         user.setAge(22);
        //         user.setPassword(UUID.randomUUID().toString());
        //         tbUserDao.insert(user);
        //     }
        // }

        TbUser user = new TbUser();
        user.setUserName("张三1212");
        user.setAge(22);
        user.setPassword(RandomUtil.randomString(6));

        log.info("静态工具类中注入动态参数-----打印日志------{}", MyTestUtils.obj2json(user));

        MyUtils.testMethod();

    }


    int info = 1;

    //    @Scheduled(fixedRate = 1000)
    // 专用线程池
    public void outputLogger() {
        log.info("测试日志输出" + info++);
    }


}
